<script setup lang="ts">
import { reactive, onMounted } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();

const state = reactive({
  overlayShow: false,
  panelHeight: Math.round(0.6 * window.innerHeight),
  inputValue: {
    place: "",
    date: "",
    time: "",
  },
});

const anchors = [
  0,
  Math.round(0.4 * window.innerHeight),
  Math.round(0.6 * window.innerHeight),
];

const planClick = () => {
  state.panelHeight = Math.round(0.4 * window.innerHeight);
};

const loading = (time?: number, fn?: () => void) => {
  state.overlayShow = true;
  setTimeout(() => {
    state.overlayShow = false;
    fn && fn();
  }, time);
};

onMounted(() => {});
</script>

<template>
  <div class="bg-img">
    <img src="@/assets/image/plan/add_plan.png" />
    <div
      class="navigateBack"
      @click="
        () => {
          router.go(-1);
        }
      "
    ></div>
  </div>
  <van-overlay :show="state.overlayShow">
    <van-loading class="wrapper" type="spinner" />
  </van-overlay>
  <van-floating-panel v-model:height="state.panelHeight" :anchors="anchors">
    <div class="panel_content">
      <div class="header">
        <span>智能规划</span>
      </div>
      <div class="content">
        <van-cell-group inset>
          <van-field
            v-model="state.inputValue.place"
            size="large"
            label="想去"
            placeholder="请输入地点"
          />
          <van-field
            v-model="state.inputValue.date"
            size="large"
            label="出发"
            placeholder="请输入时间"
          />
          <van-field
            v-model="state.inputValue.time"
            size="large"
            label="天数"
            placeholder="请输入天数"
            type="number"
          />
          <span>2成人 0儿童 ></span>
        </van-cell-group>
      </div>
      <div class="footer_box">
        <div
          class="foot_btn"
          @click="
            () => {
              state.panelHeight = 0;
              loading(800, () => router.push('/aiPlanRes'));
            }
          "
        >
          一键路线规划
        </div>
      </div>
    </div>
  </van-floating-panel>
</template>
<style scoped lang="scss">
.bg-img {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
  img {
    width: 100%;
    height: 100%;
  }
  .search {
    display: flex;
    justify-content: center;
    width: 100%;
    position: absolute;
    top: 26px;
  }
  .search_box {
    width: 95%;
  }
  .navigateBack {
    position: absolute;
    top: 29px;
    left: 12px;
    width: 40px;
    height: 50px;
    background-color: transparent;
  }
}
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.panel_content {
  padding: 0 20px;
  color: #3a3a3a;
  font-size: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .header {
    width: 100%;
    padding-bottom: 3px;
    span {
      font-weight: bold;
      font-size: 18px;
    }
  }
  .sub_header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: #595959;
    span {
      font-weight: bold;
    }
    .date {
      display: flex;
      align-items: center;
      font-weight: bold;
    }
    img {
      width: 28px;
      height: 28px;
    }
  }
  .content {
    box-sizing: border-box;
    padding: 12px 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    // justify-content: center;
    align-items: center;
    font-size: 16px;
    span {
      font-size: 15px;
    }
  }
  .footer_box {
    width: 100%;
    display: flex;
    justify-content: center;
    .foot_btn {
      box-sizing: border-box;
      width: 95%;
      padding: 8px;
      font-size: 18px;
      font-weight: bold;
      text-align: center;
      color: #fff;
      background-color: #00bf69;
      margin-top: 30px;
      border-radius: 10px;
    }
  }
}
</style>
